const { Result } = require("@/libs/result");
const { orderService } = require("./order.service");

function validatorResult(ctx) {
  return new Promise(async (resolve) => {
    try {
      const data = await ctx.getValidationResult();
      resolve([false, data]);
    } catch (err) {
      resolve([err, null]);
    }
  });
}

class OrderController {
  async createRetailOrder(ctx) {
    ctx.body = await orderService.createRetailOrder(ctx.request.body, ctx.state);
  }
  async createTableOrder(ctx) {
    ctx.body = await orderService.createTableOrder(ctx.request.body, ctx.state);
  }
  async createTableOrderProduct(ctx) {
    ctx.body = await orderService.createTableOrderProduct(ctx.request.params, ctx.request.body, ctx.state);
  }
  async paymentTableOrder(ctx) {
    ctx.body = await orderService.paymentTableOrder(ctx.request.params, ctx.request.body, ctx.state);
  }
}

module.exports = {
  orderController: new OrderController(),
};
